#ifndef COMMON_H
#define COMMON_H

#include <sys/socket.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include <syslog.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <string>
#include <arpa/inet.h>

#include "file_process.h"

#define	SA	struct sockaddr
#define	MAXLINE		4096	/* max text line length */

#define AGENT_PORT 9000
#define FLOOD_PORT 9001
#define CMD_LENGTH 1024
#define BUF_SIZE 2000
#define IP_LENGTH 16

struct command
{
        int cmd_type;
        int server_id;
        int cmd_id;
        char cmd[CMD_LENGTH];
        struct timeval cmd_time;
};

int		 Socket(int, int, int);
int		 Accept(int, SA *, socklen_t *);
void	 Bind(int, const SA *, socklen_t);
void	 Connect(int, const SA *, socklen_t);
void	 Listen(int, int);
ssize_t	 Recv(int, void *, size_t, int);
void	 Send(int, const void *, size_t, int);
void Sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
ssize_t Recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
ssize_t	 Readn(int, void *, size_t);
void	 Writen(int, void *, size_t);
void	 Setsockopt(int, int, int, const void *, socklen_t);
pid_t	 Fork(void);

void	 err_sys(const char *, ...);
void	 Close(int);
int		 Open(const char *, int,  mode_t mode = 0666);
int		 Fcntl(int, int, int);

void flood(char *msg, int length);

#endif	//COMMON_H
